#include<iostream>
using namespace std;
#include<fstream>
#include<string>


char *bconv(int num, int b) 
{
    char temp[20];
    char *p=temp;
 
     p = &temp[sizeof(temp)-1];    //Going to the end of buffer
     *p = '\0';
 
     //Converting
     while(num != 0) {
          *--p = "0123456789abcdef"[num % b];
          num /= b;
     }
     return p;
}


void main()
{
	int a,check;

	ifstream op;
	op.open("12.txt");
	string istr;

	ofstream out;
	out.open("bin.txt");

	
	while(op.eof()==0)
	{
		istr.clear();

	
	char op1[6],op2[6],op3[6],op4[6];
	
	op>>op1;
	op>>op2;
	op>>op3;
	op>>op4;
	
	cout<<op1<<endl;
	cout<<op2<<endl;
	cout<<op3<<endl;
	cout<<op4<<endl;
	
	/// now have to write in binary
	///cout<<op1[0]<<op1[1]<<endl;
	
	string add="ADD";
	string sub="SUB";
	string mul="MUL";
	string and="AND";
	string not="NOT";
	string inc="INC";
	string dec="DEC";

	//ops
	//string 

	if(add.compare(op1)==0)
	{
		cout<<"add"<<endl;
		istr.append("00001");
		check=0;
		
	}
	else if(sub.compare(op1)==0)
	{
		cout<<"sub"<<endl;
		istr.append("00010");
		check=0;
	}
	else if(mul.compare(op1)==0)
	{
		cout<<"mul"<<endl;
		istr.append("00011");
		check=0;

	}
	else if(and.compare(op1)==0)
	{
		cout<<"and"<<endl;
		istr.append("00100");
		check=0;
	}
	else if(not.compare(op1)==0)
	{
		cout<<"not"<<endl;
		istr.append("00100");
		check=1; //16 bit
	}
	else if(inc.compare(op1)==0)
	{
		cout<<"inc"<<endl;
		istr.append("00100");
		check=1;//16 bit
	}
	else if(dec.compare(op1)==0)
	{
		cout<<"dec"<<endl;
		istr.append("00100");
		check=1;//16 bit
	}

	//check operants
	string r1="r1",r2="r2",r3="r3",r4="r4",r5="r5",r6="r6",r7="r7",r8="r8",r9="r9",r10="r10";
	//for op2


	if(r1.compare(op2)==0)
	{
		istr.append("00001");
	}
	else if(r2.compare(op2)==0)
	{
		istr.append("00010");
	}
	else if(r3.compare(op2)==0)
	{
		istr.append("00011");
	}
	else if(r4.compare(op2)==0)
	{
		istr.append("00100");
	}
	else if(r5.compare(op2)==0)
	{
		istr.append("00101");
	}
	else if(r6.compare(op2)==0)
	{
		istr.append("00111");
	}
	else if(r7.compare(op2)==0)
	{
		istr.append("01000");
	}
	else if(r8.compare(op2)==0)
	{
		istr.append("01001");
	}
	else if(r9.compare(op2)==0)
	{
		istr.append("01011");
	}
	else if(r10.compare(op2)==0)
	{
		istr.append("01000");
	}


	//check operants
	string rt1="r1",rt2="r2",rt3="r3",rt4="r4",rt5="r5",rt6="r6",rt7="r7",rt8="r8",rt9="r9",rt10="r10";
	//for op2


	if(rt1.compare(op3)==0)
	{
		istr.append("00001");
	}
	else if(rt2.compare(op3)==0)
	{
		istr.append("00010");
	}
	else if(rt3.compare(op3)==0)
	{
		istr.append("00011");
	}
	else if(rt4.compare(op3)==0)
	{
		istr.append("00100");
	}
	else if(rt5.compare(op3)==0)
	{
		istr.append("00101");
	}
	else if(rt6.compare(op3)==0)
	{
		istr.append("00111");
	}
	else if(rt7.compare(op3)==0)
	{
		istr.append("01000");
	}
	else if(rt8.compare(op3)==0)
	{
		istr.append("01001");
	}
	else if(rt9.compare(op3)==0)
	{
		istr.append("01011");
	}
	else if(rt10.compare(op3)==0)
	{
		istr.append("01000");
	}

	
	
	
	
	//check operants
	string rd1="r1",rd2="r2",rd3="r3",rd4="r4",rd5="r5",rd6="r6",rd7="r7",rd8="r8",rd9="r9",rd10="r10";
	//for op2
	
	
	
	
	///////16 or 32 bit check
	if (check==1)
	{	goto bit; }




	if(rd1.compare(op3)==0)
	{
		istr.append("00001");
	}
	else if(rd2.compare(op3)==0)
	{
		istr.append("00010");
	}
	else if(rd3.compare(op3)==0)
	{
		istr.append("00011");
	}
	else if(rd4.compare(op3)==0)
	{
		istr.append("00100");
	}
	else if(rd5.compare(op3)==0)
	{
		istr.append("00101");
	}
	else if(rd6.compare(op3)==0)
	{
		istr.append("00111");
	}
	else if(rd7.compare(op3)==0)
	{
		istr.append("01000");
	}
	else if(rd8.compare(op3)==0)
	{
		istr.append("01001");
	}
	else if(rd9.compare(op3)==0)
	{
		istr.append("01011");
	}
	else if(rd10.compare(op3)==0)
	{
		istr.append("01000");
	}

bit:

	out<<istr<<endl; ///write to file


	char xd='1';
	char* b=bconv(2,2);
	cout<<b<<endl;
	//must convert in to binary string
	}



	
	op.close();
	out.close();


	/////////////End first type
	
	
	
	
	
	cin>>a;
}